//
//  ViewController.m
//  StoryAudio
//
//  Created by antl on 1/22/13.
//  Copyright (c) 2013 __MyCompanyName__. All rights reserved.
//

#import "ViewController.h"

@implementation ViewController
@synthesize ipTabBar;
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
	[self addTabBar];
}

-(void)addTabBar
{
    float yPosOff, yPosOn, tbWidth;
	UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
	if (UIDeviceOrientationIsLandscape(deviceOrientation)==TRUE) {
        if (IS_IPHONE5) {
            yPosOff = LANDSCAPE_HEIGHT;
            yPosOn = 250;
            tbWidth = 586;//480;
        }
        else
        {
            yPosOff = LANDSCAPE_HEIGHT;
            yPosOn = 250;
            tbWidth = 586;//480;
        }
	} else {
        if (IS_IPHONE5) {
            yPosOff =500 ;
            yPosOn = 500;
            tbWidth = 320;
        }
        else
        {
            yPosOff =410 ;
            yPosOn = 410;
            tbWidth = 320;
        }
	}
    if(!ipTabBar)
    {
        
        ipTabBar = [[IPLibTabBar alloc] initWithFrame:CGRectMake(0, 0, 0, TABBAR_HEIGHT)];
        ipTabBar.delegate = self;
        [self.view addSubview:ipTabBar];
        [UIView beginAnimations:nil context:nil];
		[UIView setAnimationDuration:0.05];
		[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
		ipTabBar.frame = CGRectMake(0, yPosOn, tbWidth, TABBAR_HEIGHT);
		[UIView commitAnimations];
		[ipTabBar release];
    }
    else {
		
		[UIView animateWithDuration:0.01
							  delay:0.0 
							options:UIViewAnimationOptionCurveEaseOut
						 animations:^{
							 ipTabBar.frame = CGRectMake(ipTabBar.frame.origin.x, yPosOff, tbWidth, TABBAR_HEIGHT);
						 }
						 completion:^(BOOL finished){
							 ipTabBar.delegate = nil;
							 [ipTabBar removeFromSuperview];
							 ipTabBar = nil;
						 }
		 ];
		
	}
    
}
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
	
    
    
	switch (item.tag) {
		case tagTABBAR_1:
			NSLog(@"TabBar_1");            
			break;
		case tagTABBAR_2:
            //[self jumpToPage:2];
            NSLog(@"TabBar_2");
            break;
			break;
        case tagTABBAR_4:
            //[self addTabBar];
            //[self addActionSheetwithAnimation:YES];
			break;
		default:
			break;
	}
	
}



- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    } else {
        return YES;
    }
}

@end
